package com.dianrui.moonfire.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.dianrui.moonfire.R;
import com.dianrui.moonfire.bean.InvestTop;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IncomeDetailsAdapter extends BaseAdapter {
    Context context;
    private List<InvestTop>investTopList;

    public IncomeDetailsAdapter(Context context, List<InvestTop> investTopList) {
        this.context = context;
        this.investTopList = investTopList;
    }

    public void refresh(List<InvestTop> list) {
        this.investTopList = list;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return investTopList.size();
    }

    @Override
    public Object getItem(int position) {
        return investTopList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.income_toplist_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (null != investTopList && investTopList.size()>0) {
            InvestTop investTop = investTopList.get(position);
            holder.createTimes.setText(investTop.createTime);
            holder.total.setText(investTop.total+"元");
            IncomeListDetailsAdapter incomeListDetailsAdapter=new IncomeListDetailsAdapter(context,investTop.list);
            holder.incomeListview.setAdapter(incomeListDetailsAdapter);
        }



        return convertView;
    }

     class ViewHolder {
        @BindView(R.id.create_times)
        TextView createTimes;
        @BindView(R.id.total)
        TextView total;
         @BindView(R.id.income_list)
        ListView incomeListview;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
